package player

import (
	"base"
	"center_server/logic/player/api"
	"center_server/model"
)

type playerSystem struct {
	players map[base.PlayerId]*model.Player
}

var system = new(playerSystem)

func init() {
	system.players = make(map[base.PlayerId]*model.Player)
}

func init() {
	player_api.Get = system.Get
	player_api.Add = system.Add
	player_api.Remove = system.Remove
}

func (*playerSystem) Get(playerId base.PlayerId) (result *model.Player, exists bool) {
	result, exists = system.players[playerId]
	return
}

func (*playerSystem) Add(player *model.Player) {
	system.players[player.Id()] = player
}

func (*playerSystem) Remove(playerId base.PlayerId) {
	delete(system.players, playerId)
}
